#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys, os

import win32gui
from loguru import logger

from PyQt5.QtWidgets import QApplication, QWidget

from qt_material import apply_stylesheet

sys.path.append(os.getcwd())
from views.widgets import Ui_opo_control
from utils import embed_window

class OpoControlForm(QWidget, Ui_opo_control.Ui_OPOControlForm):
    def __init__(self, parent = None):
        super(OpoControlForm, self).__init__(parent)
        self.setupUi(self)

        self.parentMainWindow = None
        self.LastStepButton.clicked.connect(self.lastStep)
        self.NextStepButton.clicked.connect(self.nextStep)

        # exePath = "C:\\Windows\\System32\\Taskmgr.exe"
        # embedWindow = embed_window.EmbedWindow(self)

        # widget = embedWindow.startProcessAndEmbedWindow(exePath, "TaskManagerWindow", "Task Manager")
        # self.horizontalLayoutOPO.addWidget(widget)
        # win32gui.SetParent(int(widget.winId()), int(self.winId()))

        logger.debug("create an instance of OpoControlForm successfully")      

    def setMainWindow(self, MainWindow):
        self.parentMainWindow = MainWindow

    def lastStep(self):
        if self.parentMainWindow is not None:
            self.parentMainWindow.opoControlLastStep()
        else:
            pass
    
    def nextStep(self):
        if self.parentMainWindow is not None:
            self.parentMainWindow.opoControlNextStep()
        else:
            pass


if __name__ == "__main__":
    app = QApplication(sys.argv)
    PAWin = OpoControlForm()
    apply_stylesheet(app, theme = "dark_teal.xml")
    PAWin.show()

    #exePath = "C:\\Windows\\system32\\calc.exe"
    # exePath = "C:\\Windows\\System32\\Taskmgr.exe"
    # embedWindow = embed_window.EmbedWindow(PAWin, exePath)

    # widget = embedWindow.embed("TaskManagerWindow", "Task Manager")
    # PAWin.horizontalLayoutOPO.addWidget(widget)
    # win32gui.SetParent(int(widget.winId()), int(PAWin.winId()))
    # PAWin.show()
    sys.exit(app.exec_())